# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
from pymongo import MongoClient


class MyspiderPipeline(object):
    def open_spider(self, spider):
        client = MongoClient("127.0.0.1", 27017)
        self.collection = client["weixin"]["item"]

    def process_item(self, item, spider):
        print('-' * 80)
        # print('公众号名称', ':', item['nickname'])
        print('标题', ':', item['title'])
        # print('发布日期', ':', item['date'])
        # print('内容', ':', item['content'])
        # print('链接', ':', item['url'])
        # print('-' * 33, item['sit'], '-' * 33)
        self.collection.insert(item)  # 存入mongodb数据库
        return item
